//
//  TJRetweetView.swift
//  WeiBo
//
//  Created by TanJian on 15/12/10.
//  Copyright © 2015年 Joshpell. All rights reserved.
//

import UIKit
import SnapKit


// 昵称的字体大小
let TJStatusNameFontSize: CGFloat = 14
// 时间与来源的字体大小
let TJStatusTimeFontSize: CGFloat = 10
// 内容字体大小
let TJStatusContentFontSize: CGFloat = 15
//cell间距
let TJCellMargin:CGFloat = 10



class TJRetweetView: UIView {

    var bottomConstraint:Constraint?
    
    private lazy var pictureView:TJStatusPicView = {
        let view = TJStatusPicView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
    
    private lazy var contentLable: UILabel = UILabel(textColor: UIColor.darkGrayColor(), fontSize: TJStatusContentFontSize, maxWidth: TJScreen.width - 2 * TJCellMargin)
    
    //设置视图模型
    var statusViewModel:TJUserDataViewModel? {
        didSet{

            contentLable.text = statusViewModel?.retweetText
            
            self.bottomConstraint?.uninstall()
            
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0{

                //设置数据
                pictureView.pic_urls = pic_urls
                pictureView.hidden = false

                snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(pictureView).offset(TJCellMargin).constraint
                })
                
            }else{
                
                pictureView.hidden = true
                
                snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(contentLable).offset(TJCellMargin).constraint
                })
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    
    private func setupUI(){
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        addSubview(contentLable)
        addSubview(pictureView)
        
        contentLable.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(TJMargin)
            make.top.equalTo(self).offset(TJMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLable)
            make.top.equalTo(contentLable.snp_bottom).offset(TJCellMargin)
        }
        
        //设置自身高度与内容高度一直
        self.snp_makeConstraints { (make) -> Void in
            self.bottomConstraint = make.bottom.equalTo(pictureView).offset(TJCellMargin).constraint
        }
    }
    
}











